#!/bin/bash
# 检测raid 阵列中磁盘的损盘和掉盘，会记录状态和时间，

saveline=100	#要保留的日志行数

stat=`/sbin/mdadm -D /dev/md1 | grep "removed"`

if [ -n "${stat}" ]
then
	/bin/echo ${stat}'     '`/bin/date +"%Y-%m-%d %H:%M:%S"` >> /home/wwwroot/default/raid_check.html
fi

stat2=`/sbin/mdadm -D /dev/md1 | grep "faulty"`
if [ -n "${stat2}" ]
then
        /bin/echo ${stat2}'     '`/bin/date +"%Y-%m-%d %H:%M:%S"` >> /home/wwwroot/default/raid_check.html
fi


if [ -z "$stat" -a -z "$stat2" ]
then
	/bin/echo '全部正常     '`date +"%Y-%m-%d %H:%M:%S"` >> /home/wwwroot/default/raid_check.html
fi


line=`/bin/cat /home/wwwroot/default/raid_check.html | wc -l`
if(($line > ${saveline}))
then
	l2=$((${line}-${saveline}))	
	/bin/sed -i 1,${l2}d /home/wwwroot/default/raid_check.html
fi
